const base62 = require('../lib/base62.js')
const assert = require('assert')

describe('base62', function () {
  it('should encode 0 correctly', function () {
    const n = 0
    const x = base62(n)
    assert.strictEqual(x, '0')
  })

  it('should encode 1 correctly', function () {
    const n = 1
    const x = base62(n)
    assert.strictEqual(x, '1')
  })

  it('should run out of numbers at 10', function () {
    const n = 10
    const x = base62(n)
    assert.strictEqual(x, 'A')
  })

  it('should run out of lowercase letters at 36', function () {
    const n = 36
    const x = base62(n)
    assert.strictEqual(x, 'a')
  })

  it('should wrap at 62', function () {
    const n = 62
    const x = base62(n)
    assert.strictEqual(x, '10')
  })

  it('should encode big number correctly', function () {
    const n = 199919991999
    const x = base62(n)
    assert.strictEqual(x, '3WDjuZz')
  })

  it('should encode biggest integer correctly', function () {
    const n = 9007199254740991 // 2^53 -1 or Number.MAX_SAFE_INTEGER
    const x = base62(n)
    assert.strictEqual(x, 'fFgnDxSe7')
  })

  it('should ignore negative numbers', function () {
    const n = -1
    const x = base62(n)
    assert.strictEqual(x, '')
  })
})
